/*****************************************************************************************
   
   Copyright (c) Microsoft Corporation. All rights reserved.

   Use of this code sample is subject to the terms of the Microsoft
   Permissive License, a copy of which should always be distributed with
   this file.  You can also access a copy of this license agreement at:
   http://www.microsoft.com/resources/sharedsource/licensingbasics/permissivelicense.mspx

 ****************************************************************************************/

using System;

namespace GrooveWebServicesV12Helpers
{
	public class Message
	{
		public enum Category
		{
			New = 0x0,
			Opened = 0x1,
			Sent = 0x2,
			Inbox = 0x3,
			All = 0x4,
			Unknown = 0xFF
		}

		private GrooveWebServicesV12Helpers.Account m_Account;
		private GrooveWebServicesV12Helpers.MessageContent m_MessageContent;
		private GrooveWebServicesV12Helpers.MessageHeader m_MessageHeader;
		
		private GrooveMessagesWebService.Message m_Message;

		public Message(GrooveWebServicesV12Helpers.Account i_Account, GrooveMessagesWebService.Message i_Message)
		{
			m_Account = i_Account;
			m_Message = i_Message;
		}

		#region Message Properties And Methods

		public static GrooveMessagesWebService.GrooveMessages CreateInitializedMessagesWebService(string i_IdentityURL, string i_TargetURI, GrooveWebServicesV12Helpers.Context i_Context)
		{
			//  Create the service
			GrooveMessagesWebService.GrooveMessages MessagesWebService = new GrooveMessagesWebService.GrooveMessages();

			//  Create the Groove SOAP header
			MessagesWebService.GrooveRequestHeaderValue = new GrooveMessagesWebService.GrooveRequestHeader();

			//  Set appropriate header values
			MessagesWebService.GrooveRequestHeaderValue.GrooveRequestKey = i_Context.RequestKey;
			MessagesWebService.GrooveRequestHeaderValue.GrooveIdentityURL = i_IdentityURL;

			//  Set the URL
			MessagesWebService.Url = i_Context.Host + i_TargetURI;

			//  Set Timeout
			MessagesWebService.Timeout = i_Context.Timeout;

			return MessagesWebService;
		}

		public GrooveWebServicesV12Helpers.Account Account
		{
			get
			{
				return m_Account;
			}
		}

		public GrooveWebServicesV12Helpers.MessageContent Content
		{
			get
			{
				if (m_MessageContent == null)
				{
					m_MessageContent = new GrooveWebServicesV12Helpers.MessageContent
						(
						m_Account,
						m_Message.MessageContent
						);
				}

				return m_MessageContent;
			}
		}

		public GrooveWebServicesV12Helpers.MessageHeader Header
		{
			get
			{
				if (m_MessageHeader == null)
				{
					m_MessageHeader = new GrooveWebServicesV12Helpers.MessageHeader
						(
						m_Account,
						m_Message.MessageHeader
						);
				}

				return m_MessageHeader;
			}
		}

		#endregion
	}
}
